
import { Controller, Inject, Get, Query, Param, Del, Post, Put, Body } from '@midwayjs/core';
import { Auth } from "../decorator/auth.decorator";
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@midwayjs/swagger';
import { BusinessType, Log } from "../decorator/log.decorator";
import { MajorService } from '@service/major.service';
import { CreateMajorDto, UpdateMajorDto, QueryMajorDto} from '@dto/major.dto';

@ApiTags('专业信息')
@Controller('system/major')
export class MajorController {
  @Inject()
  majorService: MajorService;
  // 创建
  @ApiOperation({ summary: '创建专业信息', description: '创建新的专业信息记录' })
  @ApiBody({ type: CreateMajorDto, description: '专业信息信息数据' })
  @ApiResponse({ status: 200, description: '创建成功' })
  @Auth('system:major:add')
  @Log({ title: '专业信息-创建', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() body: CreateMajorDto) {
    return await this.majorService.create(body);
  }
  // 获取列表
  @ApiOperation({ summary: '获取专业信息列表', description: '分页查询专业信息信息列表' })
  @ApiResponse({ status: 200, description: '查询成功' })
  @Auth('system:major:query')
  @Log({ title: '专业信息-列表', businessType: BusinessType.LIST })
  @Get('/list')
  async list(@Query() query: QueryMajorDto) {
    return await this.majorService.list(query);
  }

  // 根据年级ID获取专业列表
  @ApiOperation({ summary: '根据年级ID获取专业列表', description: '根据年级ID查询该年级下的所有专业' })
  @ApiParam({ name: 'gradeId', description: '年级ID', type: 'number' })
  @ApiResponse({ status: 200, description: '查询成功' })
  @Auth('system:major:query')
  @Log({ title: '专业信息-按年级查询', businessType: BusinessType.LIST })
  @Get('/listByGrade/:gradeId')
  async listByGrade(@Param('gradeId') gradeId: string) {
    return await this.majorService.listByGrade(+gradeId);
  }
  // 获取详情
  @ApiOperation({ summary: '获取专业信息详情', description: '根据majorId查询专业信息详细信息' })
  @ApiParam({ name: 'majorId', description: 'majorId值' })
  @ApiResponse({ status: 200, description: '查询成功' })
  @Auth('system:major:query')
  @Log({ title: '专业信息-详情', businessType: BusinessType.DETAIL })
  @Get('/:majorId')
  async detail(@Param('majorId') majorId: string) {
    return await this.majorService.detail(majorId);
  }
  // 修改
  @ApiOperation({ summary: '修改专业信息', description: '根据majorId修改专业信息信息' })
  @ApiBody({ type: UpdateMajorDto, description: '更新的专业信息信息数据' })
  @ApiResponse({ status: 200, description: '修改成功' })
  @Auth('system:major:edit')
  @Log({ title: '专业信息-修改', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() body: UpdateMajorDto) {
    return await this.majorService.update(body);
  }
  // 删除
  @ApiOperation({ summary: '删除专业信息', description: '根据majorId删除专业信息记录' })
  @ApiParam({ name: 'majorId', description: 'majorId值' })
  @ApiResponse({ status: 200, description: '删除成功' })
  @Auth('system:major:remove')
  @Log({ title: '专业信息-删除', businessType: BusinessType.REMOVE })  
  @Del('/:majorId')
  async remove(@Param('majorId') majorId: string) {
    const majorIds = majorId.split(',').map((majorId) => +majorId);
    return this.majorService.remove(majorIds);
  }
  // 导出
  @ApiOperation({ summary: '导出专业信息', description: '根据查询参数导出专业信息数据' })
  @ApiBody({ type: QueryMajorDto, description: '导出查询参数' })
  @ApiResponse({ status: 200, description: '导出成功' })
  @Auth('system:major:export')
  @Log({ title: '专业信息-导出', businessType: BusinessType.EXPORT })
  @Post('/export')
  async export(@Body() queryParams: QueryMajorDto) {
    return await this.majorService.export(queryParams);
  }
}